<?php
class LoginController extends PageController{
	public function actionIndex(){
		$request = $this->getRequest();

		if($request->hasParam("link")){
			$this->link = $request->getParam("link");
		}
	}

	public function actionLogin(){
		$request = $this->getRequest();

		if($request->isPost() && $request->hasPostArray(array("gebruiker_email","gebruiker_wachtwoord"))){

			$session = Session::instance();
			$mG = new Mapper_Gebruiker();

			$gebruiker = $mG->getByLogin($request->getPost("gebruiker_email"),$request->getPost("gebruiker_wachtwoord"));

			if($gebruiker instanceof Gebruiker){
				$session->gebruiker_id = $gebruiker->gebruiker_id;

				if($request->hasParam("link")){
					list($module,$controller,$action) = explode("_",$request->link);
					die(header("location: /{$module}/{$controller}/{$action}"));
				}
			}
		}
		die(header("location: /default/login"));
	}

	public function actionLogout(){
		Session::instance()->regenerate();
		die(header("location: /"));
	}
}